// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.IO;
public class FFmpeg : ModuleRules
{
    private bool loadFFmpegLibrary(ReadOnlyTargetRules Target) {
        if (Target.Platform == UnrealTargetPlatform.Win64)
        {
            string LibraryRoot = Path.Combine(ModuleDirectory, "../../ThirdParty/x64");
            // Include path
            PublicIncludePaths.Add(Path.Combine(LibraryRoot, "include"));

            string LibrariesPath = Path.Combine(LibraryRoot, "lib");

            System.Console.WriteLine("... LibrariesPath -> " + LibrariesPath);

            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "avcodec.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "avdevice.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "avfilter.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "avformat.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "avutil.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "swresample.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "swscale.lib"));

            string[] dlls = { "avcodec-58.dll", "avdevice-58.dll", "avfilter-7.dll", "avformat-58.dll", "avutil-56.dll", "swresample-3.dll", "swscale-5.dll", "postproc-55.dll" };

            string BinariesPath = Path.Combine(LibraryRoot, "bin");
            foreach (string dll in dlls)
            {
                PublicDelayLoadDLLs.Add(dll);
                //CopyToBinaries(Path.Combine(BinariesPath, dll), Target);
                RuntimeDependencies.Add(Path.Combine("$(BinaryOutputDir)", dll), Path.Combine(BinariesPath, dll));
            }

            // Ensure that the DLL is staged along with the executable
            //RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/FFmpegLibrary/Win64/ExampleLibrary.dll");
        }
        return true;
    }
	public FFmpeg(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
		
		PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
			}
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"Projects"
				// ... add other public dependencies that you statically link with here ...
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

        loadFFmpegLibrary(Target);
	}
}
